<?php
$domain_list = array();

if(isset($_REQUEST['domains']) && isset($_POST['Submit']) ) {
	
	$temp = explode("\n", $_REQUEST['domains']);

	foreach ($temp as $d ) {

		$d = trim($d);

		if (!empty($d) && count($domain_list) <= 20 ) {
			$domain_list[] = $d;
		}
	}
}

//##########################################

$results = array();

if (count($domain_list) >= 2 ) {

	$i = 0;

	foreach ($domain_list as $domain ) {

		$ip = gethostbyname($domain);

		if ($ip == $domain ) {

			$results['unknown'][$i]['d'] = $domain;
			$results['unknown'][$i]['ip'] = $ip;
		} else {

			$c = get_class_c($ip);

			$results[$c][$i]['d'] = $domain;
			$results[$c][$i]['ip'] = $ip;
		}

		$i++;
	}
?>
<br>
<br>
<table width="500" border="0" cellspacing="1" cellpadding="1" align="center">
  <tr class="headingbar">
    <td width="33%" height="25" align="left"><strong>Domain Name </strong></td>
    <td width="37%" height="25" align="center"><strong>IP Address </strong></td>
    <td width="30%" height="25" align="center"><strong>Class C </strong></td>
  </tr>
<?php
$k = 0;
foreach ($results as $c => $det )
{
	foreach ($det as $defs ) {
?>
  <tr class="tr<?php echo (($k%2 == 0)?'1':'2'); ?>">
    <td align="left"><?php echo $defs['d']; ?></td>
    <td align="center"><?php echo $defs['ip']; ?></td>
    <td align="center"><?php echo $c; ?></td>
  </tr>
<?php
	$k++;
	}
}
?>
</table>
<?php
}
//############################################

function get_class_c($ip) {

	$str = explode('.', $ip);

	return $str[0].'.'.$str[1].'.'.$str[2];
}
?>
